<template>
  <div>
    <div class="search-box">
      <div class="search-box-left">
        <el-input class="search-box-left-input" @keyup.enter.native="getList" v-model="startUserName"
          placeholder="请输入内容"></el-input>
      </div>
      <div class="search-box-right">
        审批类型：
        <el-select v-model="approvalType" placeholder="请选择审批类型" @change="selectApproval">
          <el-option v-for="item in approvalOptions" :key="item.value" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
      </div>
    </div>

    <div class="wrap" v-loading="loading2">
      <el-tabs :tab-position="tabPosition" style="height: 400px;" v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="我审批的">
          <div class="overflow" v-if="historyTaskData.length > 0">
            <div class="wrap-items" v-for="(item, index) in historyTaskData" :key="index">
               <div class="wrap-items-left">
                <div class="wrap-items-left-check">
                  <el-checkbox v-model="item.isChecked"></el-checkbox>
                </div>
              </div>
              <div class="wrap-items-middle">
                <div class="wrap-items-middle-title">
                  <div class="first-name">
                    <img v-if="item.startUserHeadIcon" :src="item.startUserHeadIcon">
                    <img v-else src="../../../assets/card/morenh.png">
                  </div>
                  <div class="wrap-items-middle-title-content">{{ item.startUser }}提交的{{ item.schemeName }}</div>
                </div>
                <div class="wrap-items-middle-type">
                  <div class="wrap-items-middle-type-left">审批编码:</div>
                  <div class="wrap-items-middle-type-right">{{ item.data.approval_code }}</div>
                </div>
                <div class="wrap-items-middle-type">
                  <div class="wrap-items-middle-type-left">招标负责人:</div>
                  <div class="wrap-items-middle-type-right">{{ item.data.bidding_contract }}元</div>
                </div>
                <div class="wrap-items-middle-type">
                  <div class="wrap-items-middle-type-left">招标名称:</div>
                  <div class="wrap-items-middle-type-right">{{ item.data.bidding_name }}</div>
                </div>
                <div class="wrap-items-middle-type">
                  <div class="wrap-items-middle-type-left">招标数量:</div>
                  <div class="wrap-items-middle-type-right">{{ item.data.bidding_number }}</div>
                </div>
              </div>
              <div class="wrap-items-right">
                <div class="wrap-items-left-adopt">
                  <div class="refuse" v-if="item.status == 0">审批拒绝</div>
                  <div class="adopt" v-else-if="item.status == 1">审批通过</div>
                  <div class="processing" v-else>审批中</div>
                </div>
              </div>
            </div>
          </div>
          <div class="approval-no-data" v-else>
            <img src="../../../assets/flowlist/no-data.png">
          </div>
        </el-tab-pane>
        <el-tab-pane label="我发起的">
          <div class="overflow" v-if="myTaskData.length > 0">
            <div class="wrap-items" v-for="(item, index) in myTaskData" :key="index">
              <div class="wrap-items-left">
                <div class="wrap-items-left-check">
                  <el-checkbox v-model="item.isChecked"></el-checkbox>
                </div>
              </div>
              <div class="wrap-items-middle">
                <div class="wrap-items-middle-title">
                  <div class="first-name">
                    <img v-if="item.startUserHeadIcon" :src="item.startUserHeadIcon">
                    <img v-else src="../../../assets/card/morenh.png">
                  </div>
                  <div class="wrap-items-middle-title-content">{{ item.startUser }}提交的{{ item.schemeName }}</div>
                </div>
                <div class="wrap-items-middle-type">
                  <div class="wrap-items-middle-type-left">审批编码:</div>
                  <div class="wrap-items-middle-type-right">{{ item.data.approval_code }}</div>
                </div>
                <div class="wrap-items-middle-type">
                  <div class="wrap-items-middle-type-left">招标负责人:</div>
                  <div class="wrap-items-middle-type-right">{{ item.data.bidding_contract }}元</div>
                </div>
                <div class="wrap-items-middle-type">
                  <div class="wrap-items-middle-type-left">招标名称:</div>
                  <div class="wrap-items-middle-type-right">{{ item.data.bidding_name }}</div>
                </div>
                <div class="wrap-items-middle-type">
                  <div class="wrap-items-middle-type-left">招标数量:</div>
                  <div class="wrap-items-middle-type-right">{{ item.data.bidding_number }}</div>
                </div>
              </div>
              <div class="wrap-items-right">
                <div class="wrap-items-left-adopt">
                  <div class="refuse" v-if="item.status == 0">审批拒绝</div>
                  <div class="adopt" v-else-if="item.status == 1">审批通过</div>
                  <div class="processing" v-else>审批中</div>
                </div>
              </div>
            </div>
          </div>
          <div class="approval-no-data" v-else>
            <img src="../../../assets/flowlist/no-data.png">
          </div>
        </el-tab-pane>
        <el-tab-pane label="我收到的">
          <div class="overflow" v-if="manualTaskData.length > 0">
            <div class="wrap-items" v-for="(item, index) in manualTaskData" :key="index">
               <div class="wrap-items-left">
                <div class="wrap-items-left-check">
                  <el-checkbox v-model="item.isChecked"></el-checkbox>
                </div>
              </div>
              <div class="wrap-items-middle">
                <div class="wrap-items-middle-title">
                  <div class="first-name">
                    <img v-if="item.startUserHeadIcon" :src="item.startUserHeadIcon">
                    <img v-else src="../../../assets/card/morenh.png">
                  </div>
                  <div class="wrap-items-middle-title-content">{{ item.startUser }}提交的{{ item.schemeName }}</div>
                </div>
                <div class="wrap-items-middle-type">
                  <div class="wrap-items-middle-type-left">审批编码:</div>
                  <div class="wrap-items-middle-type-right">{{ item.data.approval_code }}</div>
                </div>
                <div class="wrap-items-middle-type">
                  <div class="wrap-items-middle-type-left">招标负责人:</div>
                  <div class="wrap-items-middle-type-right">{{ item.data.bidding_contract }}元</div>
                </div>
                <div class="wrap-items-middle-type">
                  <div class="wrap-items-middle-type-left">招标名称:</div>
                  <div class="wrap-items-middle-type-right">{{ item.data.bidding_name }}</div>
                </div>
                <div class="wrap-items-middle-type">
                  <div class="wrap-items-middle-type-left">招标数量:</div>
                  <div class="wrap-items-middle-type-right">{{ item.data.bidding_number }}</div>
                </div>
              </div>
              <div class="wrap-items-right">
                <div class="wrap-items-left-adopt">
                  <div class="refuse" v-if="item.status == 0">审批拒绝</div>
                  <div class="adopt" v-else-if="item.status == 1">审批通过</div>
                  <div class="processing" v-else>审批中</div>
                </div>
              </div>
            </div>
          </div>
          <div class="approval-no-data" v-else>
            <img src="../../../assets/flowlist/no-data.png">
          </div>
        </el-tab-pane>
      </el-tabs>
    </div>
    <div class="el-paganation">
      <el-pagination class="el-paganation-i" background @current-change="handleCurrentChange"
        layout="total,prev, pager, next" :total="total">
      </el-pagination>

    </div>
  </div>
</template>
<script>
import { getMyTask, getHistoryTask, getManualTask } from "@/api/workFlow/WFProcess";//我的流程
export default {
  props: {
  },
  data() {
    return {
      tabPosition: 'left',
      activeName: 0,
      total: 0,
      //查询条件
      limit: 1,//当前页数
      size: 5,//每页大小
      approvalType: '招标审批',// 审批类型
      approvalOptions: [{
        label: '招标审批',
        value: '招标审批'
      }],
      startUserName: '',
      //我审批的：已办
      historyTaskData: [],
      historyTaskTotal: 0,
      //我发起的：我的流程
      myTaskData: [],
      myTaskTotal: 0,
      //我收到的：传阅
      manualTaskData: [],
      manualTaskTotal: 0,
      loading2:false,
    }
  },
  async mounted() {
    //我审批的：已办
    await this.getHistoryTask()
    //我发起的：我的流程
    await this.getMyTask()
    // 我收到的：传阅
    await this.getManualTask()
  },
  methods: {
    init(){
      if(this.activeName == 0){
        this.getHistoryTask()
      }else if(this.activeName == 1){
        this.getMyTask()
      }else{
        this.getManualTask()
      }
    },
    getHistoryTask() {
      let params = {
        limit: this.limit,
        size: this.size,
        order: 'desc',
        approvalType: this.approvalType,//审批类型
        startUserName: this.startUserName,//发起人
      }
      this.loading2 = true
      getHistoryTask(params).then(res => {
        if (res.data.success) {
          this.loading2 = false
          this.historyTaskData = res.data.data.Rows
          this.historyTaskTotal = res.data.data.Total
          this.total = this.historyTaskTotal
        }
      })
    },
    getMyTask() {
      let params = {
        limit: this.limit,
        size: this.size,
        order: 'desc',
        approvalType: this.approvalType,//审批类型
        startUserName: this.startUserName,//发起人
      }
      this.loading2 = true
      getMyTask(params).then(res => {
        if (res.data.success) {
          this.loading2 = false
          this.myTaskData = res.data.data.Rows
          this.myTaskTotal = res.data.data.Total
        }
      })
    },
    getManualTask() {
      let params = {
        limit: this.limit,
        size: this.size,
        order: 'desc',
        approvalType: this.approvalType,//审批类型
        startUserName: this.startUserName,//发起人
      }
      this.loading2 = true
      getManualTask(params).then(res => {
        if (res.data.success) {
          this.loading2 = false
          this.manualTaskData = res.data.data.Rows
          this.manualTaskTotal = res.data.data.Total
          // this.total = this.manualTaskTotal
        }
      })
    },

    selectApproval() {
      if (this.activeName == 0) {
        this.getHistoryTask()
      } else if (this.activeName == 1) {
        this.getMyTask()
      } else if (this.activeName == 2) {
        this.getManualTask()
      }
    },
    getList() {
      if (this.activeName == 0) {
        this.getHistoryTask()
      } else if (this.activeName == 1) {
        this.getMyTask()
      } else if (this.activeName == 2) {
        this.getManualTask()
      }
    },
    handleClick() {
      if (this.activeName == 0) {
        this.getHistoryTask()
        this.total = this.historyTaskTotal
      } else if (this.activeName == 1) {
        this.getMyTask()
        this.total = this.myTaskTotal
      } else if (this.activeName == 2) {
        this.getManualTask()
        this.total = this.manualTaskTotal
      }
    },
    handleCurrentChange(currentPage) {
      this.limit = currentPage
      //判断选项卡，然后决定调用哪个接口
      if (this.activeName == 0) {
        this.getHistoryTask()
      } else if (this.activeName == 1) {
        this.getMyTask()
      }

    },
  }
}
</script>

<style scoped>
/* 关联审批单开始 */
::v-deep .el-dialog__footer {
  border-top: 1px solid #eee;
}

.height16 {
  height: 16px;
}

.wrap {
  height: 400px;
  border: 1px solid #eee;
  display: flex;
  flex-direction: row;
}

.wrap-items {
  width: 720px;
  border-bottom: 1px solid #eee;
  display: flex;
  flex-direction: row;
}

.wrap-items-left {
  height: 100%;
  width: 10%;
}

.wrap-items-left-check {
  width: 100%;
  height: 40px;
  margin-top: 16px;
  text-align: center;
}

.adopt {
  width: 71px;
  height: 30px;
  background: #D8F8DD;
  border-radius: 3px;
  font-size: 14px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #10A300;
  line-height: 30px;
  text-align: center;
  margin: 0 auto;
}

.refuse {
  width: 71px;
  height: 30px;
  background: #FFEBEB;
  border-radius: 3px;
  font-size: 14px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #FD513B;
  line-height: 30px;
  text-align: center;
  margin: 0 auto;
}

.processing {
  width: 71px;
  height: 30px;
  background: #FFF2E0;
  border-radius: 3px;
  font-size: 14px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #FE8B04;
  line-height: 30px;
  text-align: center;
  margin: 0 auto;
}

.wrap-items-middle {
  height: 100%;
  width: 65%;
}

.wrap-items-right {
  height: 100%;
  width: 15%;
}

.wrap-items-left-adopt {
  margin-top: 16px;
}

.wrap-items-middle-title {
  margin-top: 16px;
  display: flex;
  flex-direction: row;
}

.first-name {
  width: 40px;
  height: 40px;
  border-radius: 4px;
}

.first-name>img {
  width: 100%;
  height: 100%;
}

.wrap-items-middle-title-content {
  font-size: 16px;
  font-family: PingFang-SC-Bold, PingFang-SC;
  font-weight: 400;
  color: #333333;
  line-height: 40px;
  margin-left: 16px;
}

.wrap-items-middle-type {
  display: flex;
  flex-direction: row;
}

.wrap-items-middle-type-left {
  width: 20%;
  height: 100%;
  font-size: 14px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #999999;
}

.wrap-items-middle-type-right {
  font-size: 14px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #555555;
}

.overflow {
  height: 400px;
  overflow: scroll;
}

.del_items {
  width: 350px;
  height: 32px;
  margin-top: 4px;
  background: rgb(246, 246, 246);
  border-radius: 4px;
  display: flex;
  flex-direction: row;

}

.del-items-left {
  width: 32px;
  height: 32px;
  text-align: center;
}

.del-items-left>img {
  width: 22px;
  height: 22px;
  margin-top: 5px;
}

.del-items-middle {
  width: 180px;
  height: 32px;
  font-size: 16px;
  font-weight: 400;
  text-align: left;
  line-height: 32px;
}

.del-items-processing {
  width: 80px;
  font-size: 16px;
  font-weight: 400;
  text-align: center;
  line-height: 32px;
  color: #FE8B04;
}

.del-items-refuse {
  width: 80px;
  font-size: 16px;
  font-weight: 400;
  text-align: center;
  line-height: 32px;
  color: #FD513B;
}

.del-items-adopt {
  width: 80px;
  font-size: 16px;
  font-weight: 400;
  text-align: center;
  line-height: 32px;
  color: #10A300;
}

.del-items-right {
  width: 90px;
  height: 32px;
}

.del-items-close {
  width: 32px;
  height: 32px;
  margin-left: 24px;
}

.search-box {
  width: 100%;
  height: 32px;
  margin: 8px 0;
  display: flex;
  flex-direction: row;
}

.search-box-left {
  width: 50%;
  height: 32px;
  text-align: center;
}

.search-box-left-input {
  width: 300px;
}

.search-box-right {
  width: 50%;
  height: 32px;
  text-align: center;
}

.el-paganation {
  width: 100%;
  height: 40px;
  text-align: center;
}

.el-paganation-i {
  margin-top: 16px;
}
.approval-no-data{
    width: 720px;
    height: 400px;
    text-align: center;
  }
  .approval-no-data::after{
    content: "";
    display: inline-block;
    height: 100%;
    width: 1px;
    vertical-align: middle;
  }
  .approval-no-data>img{
    vertical-align: middle;
  }
</style>